---
category: String
created: '2021-05-31'
title: Remove duplicate lines of a text document
updated: '2021-10-13'
---

**JavaScript version**

```js removeDuplicateLines.js
const removeDuplicateLines = (str) => Array.from(new Set(str.split(/\r?\n/))).join('\n');
```

**TypeScript version**

```ts removeDuplicateLines.ts
const removeDuplicateLines = (str: string): string => Array.from(new Set(str.split(/\r?\n/))).join('\n');
```

**Examples**

```js examples.js
removeDuplicateLines(`one
three
two
three
one
four`);

/* Output */
/*
one
three
two
four
*/
```
